package com.suoluo.zenadmin.controllers.admin.classify;

import java.util.List;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.common.JSONPageData;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.classify.StyleService;
import com.suoluo.zenadmin.service.dest.DestFeatureCategoryService;
import com.suoluo.zenadmin.vo.PageVO;
import com.suoluo.zenadmin.vo.classify.HomeStyleVO;

@Path("/")
public class StyleController {

	@Resource(name="styleService")
	private StyleService styleService;
	
	@Resource(name="categoryService")
	private DestFeatureCategoryService categoryService;
	
	@Get("vlist")
	public String toListStyleHome()
	{
		return "listHomeStyleItem";
	}
	@JSON
	@Post("list")
	public Object listStyleHome(PageVO page)
	{
		JSONPageData data = new JSONPageData();
		
		List<HomeStyleVO> list = styleService.findListStyleHomeItem(page);
		data.setRows(list);
		int total  = styleService.findHomeStyleCount();
		data.setTotal(total);
		return data;
	}
	@Get("vsave")
	public String toaddStyleCategory()
	{
		return "addHomeStyleItem";
	}
	@JSON
	@Post("save")
	public Object saveStyleCategory(HomeStyleVO styleVO)
	{
		styleService.saveStyle(styleVO);
		return CommonResp.SUCCESS;
	}
	@Get("vupdate")
	public String toUpdateStyle(Invocation invo,@Param("homeStyleId")int styleId)
	{
		HomeStyleVO stylePOJO = styleService.findHomeStyleItemById(styleId);
		invo.addModel("homeStyleItem",stylePOJO);
		return "updateHomeStyleItem";
	}
	@JSON
	@Post("update")
	public Object updateStyle(HomeStyleVO styleVO)
	{
		styleService.updateStyle(styleVO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("delete")
	public Object deleteStyle(HomeStyleVO styleVO)
	{
		styleService.deleteStyle(styleVO);
		return CommonResp.SUCCESS;
	}
	@Get("syn/count")
	public String updateStyleCount(@Param("homeStyleId")int homeStyleId,@Param("categoryId")int categoryId)
	{
		styleService.updateStyleCount(homeStyleId,categoryId);
		return "listHomeStyleItem";
	}
	@JSON
	@Post("category/list")
	public Object listParentCategory()
	{
//		return styleService.findListParentCategory();
		return categoryService.findRootCategoryWithoutHotel();
	}
}
